package jimo.springboot.config;

import jimo.springboot.myInterceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MVCconfig implements WebMvcConfigurer {
    /***
     * 通过@Bean注解，将我们定义的拦截器注册到Spring容器
     * @return */
    @Bean
    public LoginInterceptor loginInterceptor(){
        return new LoginInterceptor();
    }
    /***
     * 重写接口中的addInterceptors方法，添加自定义拦截器
     * ant path路径匹配通配符
     * ‘?’  匹配任何单字符
     * ‘*’ 匹配0或者任意数量的字符
     * ‘/**’ 匹配0或者更多的目录
     * @param registry */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
       registry.addInterceptor(this.loginInterceptor()).addPathPatterns("/**");
    }
}
